package com.costaccounting.base.controller;

import java.util.List;

import com.costaccounting.common.core.domain.entity.SysDept;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.costaccounting.common.annotation.Log;
import com.costaccounting.common.core.controller.BaseController;
import com.costaccounting.common.core.domain.AjaxResult;
import com.costaccounting.common.enums.BusinessType;
import com.costaccounting.base.domain.ZsCategory;
import com.costaccounting.base.service.IZsCategoryService;
import com.costaccounting.common.utils.poi.ExcelUtil;
import com.costaccounting.common.core.page.TableDataInfo;

/**
 * 类目管理Controller
 * 
 * @author H
 * @date 2021-11-06
 */
@RestController
@RequestMapping("/base/category")
public class ZsCategoryController extends BaseController
{
    @Autowired
    private IZsCategoryService zsCategoryService;

//    /**
//     * 查询类目管理列表
//     */
//    @PreAuthorize("@ss.hasPermi('base:category:list')")
//    @GetMapping("/list")
//    public TableDataInfo list(ZsCategory zsCategory)
//    {
//        startPage();
//        List<ZsCategory> list = zsCategoryService.selectZsCategoryList(zsCategory);
//        return getDataTable(list);
//    }

    /**
     * 获取类目管理列表
     */
    @PreAuthorize("@ss.hasPermi('base:category:list')")
    @GetMapping("/list")
    public AjaxResult list(ZsCategory zsCategory)
    {
        List<ZsCategory> list = zsCategoryService.selectZsCategoryList(zsCategory);
        return AjaxResult.success(list);
    }


    /**
     * 导出类目管理列表
     */
    @PreAuthorize("@ss.hasPermi('base:category:export')")
    @Log(title = "类目管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(ZsCategory zsCategory)
    {
        List<ZsCategory> list = zsCategoryService.selectZsCategoryList(zsCategory);
        ExcelUtil<ZsCategory> util = new ExcelUtil<ZsCategory>(ZsCategory.class);
        return util.exportExcel(list, "类目管理数据");
    }


    /**
     * 根据pid获取排序
     */
    @GetMapping(value = "getSeqByPid/{pid}")
    public AjaxResult getSeqByPid(@PathVariable("pid") Long pid)
    {
        return zsCategoryService.getSeqByPid(pid);
    }

    /**
     * 获取类目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:category:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(zsCategoryService.selectZsCategoryById(id));
    }

    /**
     * 新增类目管理
     */
    @PreAuthorize("@ss.hasPermi('base:category:add')")
    @Log(title = "类目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZsCategory zsCategory)
    {
        return toAjax(zsCategoryService.insertZsCategory(zsCategory));
    }

    /**
     * 修改类目管理
     */
    @PreAuthorize("@ss.hasPermi('base:category:edit')")
    @Log(title = "类目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZsCategory zsCategory)
    {
        return toAjax(zsCategoryService.updateZsCategory(zsCategory));
    }

    /**
     * 删除类目管理
     */
    @PreAuthorize("@ss.hasPermi('base:category:remove')")
    @Log(title = "类目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return zsCategoryService.deleteByIds(ids);
    }
}
